import PropTypes from "prop-types";
import { Descriptions, Icon } from "antd";
import { routerRedux } from "react-router-dom";
import DescriptionList from "@/components/DescriptionList";
import * as G from "@/utils/common";

const { Description } = DescriptionList;

// 东风车况
const DFPVStatus = ({ status, dispatch, brandId }, { dicData }) => {
  const {
    kmTotal,
    eachFuel,
    teau,
    thuile,
    conso,
    nivHuile,
    nbJourMaintenance,
    address,
    lat,
    lon,
  } = status;
  return (
    <Descriptions title="车况信息" column={3} style={{ marginBottom: 16 }}>
      <Description label="总行驶里程">{kmTotal}</Description>
      <Description label="油耗">
        {G.isNotEmptyAndNil(eachFuel) ? `${eachFuel / 1000000}` : ""}
      </Description>
      <Description label="水温">{teau}</Description>
      <Description label="油温">{thuile}</Description>
      <Description label="油量">
        {G.isNotEmptyAndNil(conso) ? `${conso / 1000000} L` : ""}
      </Description>
      <Description label="燃油水平">{nivHuile}</Description>
      <Description label="距离下次保养天数">
        {nbJourMaintenance}
      </Description>
      <Description label="车辆当前位置" span={2}>
          <a
            onClick={() => {
              sessionStorage.setItem("vehicleLocation_position", `${lon}, ${lat}, ${address}`);
              dispatch(
                routerRedux.push({
                  pathname: "/deviceManager/vehicle/vehicleStatusCarPosition",
                  rowData: sessionStorage.getItem('rowData'),
                  sourceName: sessionStorage.getItem('sourceName'),
                  query: sessionStorage.getItem('query')
                })
              );
            }}
          >
            {lon && lat && (
              <div><Icon type="environment" theme="twoTone" /> {address}[{lon}, {lat}]</div>
            )}

          </a>
      </Description>
    </Descriptions>
  );
};

DFPVStatus.contextTypes = {
  dicData: PropTypes.any,
};

// 最后返回的VehicleFlow
const VehicleStatus = ({ status, brandId, dispatch }) => {
  const flowMap = new Map([
    ["DFPV", <DFPVStatus status={status} dispatch={dispatch} brandId={brandId} />],
  ]);
  return flowMap.get(brandId) ? (
    flowMap.get(brandId)
  ) : (
    <DFPVStatus status={status} dispatch={dispatch} brandId={brandId} />
  );
};

export default VehicleStatus;
